package cn.tedu.cart.contrller;

import cn.tedu.cart.service.CartService;
import cn.tedu.pojo.param.CartAddParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import result.JsonResult;

@RestController
public class CartController {
    @Autowired
    private CartService cartService;

    //新增购物车
    @PostMapping("/cart/add")
    public JsonResult addCart(CartAddParam param) {
        //TODO 调用业务层
        cartService.addCart(param);
        //使用JsonResult 不需要携带查询数据返回 直接返回
        return JsonResult.ok("ok");//和前端约定好的结果 {"state":200,"message":"ok","data":null}
    }

    //删除购物车，基于用户删除对应的商品
    @PostMapping("/cart/delete")
    public JsonResult deleteCart(@RequestParam("productCode") String productCode,
                                 @RequestParam("userId") String userId) {
        cartService.deleteCart(productCode, userId);
        return JsonResult.ok("删除成功");
    }
}
